package routers

import (
	"net/http"

	"github.com/gin-gonic/gin"

	_ "github.com/EDDYCJY/go-gin-example/docs"
	ginSwagger "github.com/swaggo/gin-swagger"
	"github.com/swaggo/gin-swagger/swaggerFiles"

	"github.com/EDDYCJY/go-gin-example/controllers/bill"
	"github.com/EDDYCJY/go-gin-example/controllers/goods"
	"github.com/EDDYCJY/go-gin-example/controllers/institution"
	login "github.com/EDDYCJY/go-gin-example/controllers/login"
	"github.com/EDDYCJY/go-gin-example/controllers/streamer"
	"github.com/EDDYCJY/go-gin-example/middleware/jwt"
	"github.com/EDDYCJY/go-gin-example/pkg/export"
	"github.com/EDDYCJY/go-gin-example/pkg/qrcode"
	"github.com/EDDYCJY/go-gin-example/pkg/upload"
	"github.com/EDDYCJY/go-gin-example/routers/api"
	"github.com/EDDYCJY/go-gin-example/routers/api/syscore"
)

// InitRouter initialize routing information
func InitRouter() *gin.Engine {
	r := gin.New()
	r.Use(gin.Logger())
	r.Use(gin.Recovery())

	//大后台
	syscore.SyscoreRouter(r)

	r.StaticFS("/export", http.Dir(export.GetExcelFullPath()))
	r.StaticFS("/upload/images", http.Dir(upload.GetImageFullPath()))
	r.StaticFS("/qrcode", http.Dir(qrcode.GetQrCodeFullPath()))

	r.POST("/auth", api.GetAuth)
	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
	r.POST("/upload", api.UploadImage)

	apiv1 := r.Group("/api/v1")
	//登录
	apiv1.POST("/login", login.Login)
	//刷新 token
	apiv1.GET("/ali_refresh_token", login.AliRefreshToken)
	//刷新 token
	apiv1.POST("/refresh_token", login.RefreshToken)
	//抖音登录
	apiv1.GET("/dy_login", login.DyLogin)
	//导入商品
	apiv1.POST("/add_goods", goods.AddGoods)
	//机构商品列表
	apiv1.GET("/get_goods", goods.GetGoods)
	//导入账单
	apiv1.POST("/add_bill", bill.AddBill)
	apiv1.Use(jwt.JWT())
	{
		//获取账单列表
		apiv1.GET("/get_bill", institution.GetBill)
		//获取主播列表
		apiv1.GET("/streamer", streamer.GetStreamer)
		//新建主播
		apiv1.POST("/streamer", streamer.AddStreamer)
		//更新指定主播
		apiv1.PUT("/streamer/:id", streamer.EditStreamer)
		//删除指定主播
		apiv1.DELETE("/streamer/:id", streamer.DeleteStreamer)

		//获取商品列表
		apiv1.GET("/institution/goods", institution.GetGoods)
		//新建商品
		apiv1.POST("/institution/goods", institution.AddGoods)
		//更新指定商品
		apiv1.PUT("/institution/goods/:id", institution.EditGoods)
		//更新绑定主播
		apiv1.PUT("/institution/goods_streamer/:id", institution.EditGoodsStreamer)
		//删除指定商品
		apiv1.DELETE("institution/goods/:id", institution.DeleteGoods)

		//获取样品列表
		apiv1.GET("/institution/sample", institution.GetSample)
		//新建样品
		apiv1.POST("/institution/sample", institution.AddSample)
		//更新指定样品
		apiv1.PUT("/institution/sample/:id", institution.EditSample)

		//获取子账号列表
		apiv1.GET("/institution/sub_account", institution.GetSubAccount)
		//新建子账号
		apiv1.POST("/institution/sub_account", institution.AddSubAccount)
		//更新指定子账号
		apiv1.PUT("/institution/sub_account/:id", institution.EditSubAccount)
		//删除指定子账号
		apiv1.DELETE("/institution/sub_account/:id", institution.DeleteSubAccount)

		//获取标签列表
		apiv1.GET("/institution/tag", institution.GetTag)
		//新建标签
		apiv1.POST("/institution/tag", institution.AddTag)
		//更新指定标签
		apiv1.PUT("/institution/tag/:id", institution.EditTag)
		//删除指定标签
		apiv1.DELETE("/institution/tag/:id", institution.DeleteTag)
	}

	return r
}
